Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: add logfile for e2e tests #1775

Merged
merged 2 commits into from
Feb 2, 2025
Merged

e2e: add logfile for e2e tests #1775

merged 2 commits into from
Feb 2, 2025

Conversation

parikshithb
Copy link
Member

@parikshithb parikshithb commented Jan 28, 2025

  • Creates a log file (ramen-e2e.log) in the current directory by default.
  • Log DEBUG level messages to the file and INFO level messages to the console.
  • Remove caller (file:lineno) from console logs for cleaner output.
  • Added ramen-e2e and ramen-e2e.log to gitignore
  • Reverted 2cd063a , which previously redirected e2e test logs to ramen-e2e.log using tee. This change is no longer needed because the new logger implementation now writes to ramen-e2e.log by default.

Fixes: #1722

@parikshithb parikshithb marked this pull request as draft January 28, 2025 12:15
@nirs
Copy link
Member

nirs commented Jan 28, 2025

Fixes: #1722

Good to link the issue, but we should start a PR with a commit message describing the change. We can describe what was done and what will be done later. This helps people to review the change.

e2e/main_test.go Outdated Show resolved Hide resolved
e2e/main_test.go Outdated Show resolved Hide resolved
e2e/main_test.go Outdated Show resolved Hide resolved
e2e/main_test.go Outdated Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
@nirs
Copy link
Member

nirs commented Jan 28, 2025

#1723 was merged, so you need to revert 2cd063a as part of your pr.

e2e/main_test.go Show resolved Hide resolved
e2e/util/logger.go Outdated Show resolved Hide resolved
@parikshithb parikshithb force-pushed the e2e_logger branch 2 times, most recently from 13a1f0c to f242964 Compare January 30, 2025 05:34
e2e/main_test.go Outdated Show resolved Hide resolved
Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! just minor comments about comments.

e2e/test/log.go Outdated Show resolved Hide resolved
e2e/test/log.go Outdated Show resolved Hide resolved
@parikshithb parikshithb force-pushed the e2e_logger branch 3 times, most recently from 5fea441 to 895283d Compare January 30, 2025 18:07
@parikshithb parikshithb marked this pull request as ready for review January 30, 2025 18:38
@parikshithb parikshithb requested a review from nirs January 30, 2025 18:38
Copy link
Member

@nirs nirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor comment about .gitignore

.gitignore Outdated Show resolved Hide resolved
@nirs
Copy link
Member

nirs commented Jan 30, 2025

This is clear when you look at the commits, it will help to explain int the commit/pr message why we revert the previous logging hack.

This commit introduces a dedicated log file for e2e tests:

* Creates a log file (ramen-e2e.log) in the current directory by default.
* Log DEBUG level messages to the file and INFO level messages to the console.
* Remove caller (file:lineno) from console logs for cleaner output.
* Added /e2e/ramen-e2e and /e2e/ramen-e2e.log to gitignore.

Signed-off-by: Parikshith <[email protected]>
This reverts commit 2cd063a.
which previously redirected e2e test logs to ramen-e2e.log using tee. This change is no longer needed because the new logger implementation now writes to ramen-e2e.log by default.

Signed-off-by: Parikshith <[email protected]>
if err != nil {
panic(err)
}

log := logger.Sugar()
// TODO: Sync the log on exit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the best way to handle the conflict between os.Exit() and defer is to call it only once in main() or in the case of tests, in TestMain(). This also means we cannot call any function that calls os.Exit() like log.Fatal().

We can do this like this:

func TestMain(m *testing.M) {
    os.Exit(run(m))
}

func run(m *testing.M) int {
    log := ...
    defer func() {
        _ = log.Sync()
    }()
    
    ...
    if err != nil {
        log.Errorf("error message... : %s", err)
        return 1
    }

    return m.Run()
}

With this we ensure that test failure or setup failure will return non-zero exit code, and defer function will run, and the code is very simple.

But lets no dalay this good change, we can improve this later.

@nirs nirs merged commit c1335df into RamenDR:main Feb 2, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e2e: Add logfile
2 participants